﻿
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class JiaoShouJia : MonoBehaviour
{

    public delegate void OnScaffoldHandler();
    public event OnScaffoldHandler OnNearJiaoShouJia;
    public event OnScaffoldHandler OnOver;


    public GameObject cameraEye;
    private Animator ani;
    void Start()
    {
        OnNearJiaoShouJia += PlayAnimation;
        ani = GetComponent<Animator>();
    }
    void Update()
    {
        float distance = Vector3.Distance(cameraEye.transform.position, transform.position);

        if (distance < 5)
        {
            OnNearJiaoShouJia();
        }
    }

    void PlayAnimation()
    {
        ani.SetBool("isPlay", true);
    }

    /// <summary>
    /// 动画回掉
    /// </summary>
    public void PlayFallDownSound()
    {
        SoundManager.instance.Play("downHit");
        Invoke("GameOver",3f);
    }

    void GameOver()
    {
        OnOver();
    }
}
